﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using kwzx.kq;

namespace kwzx
{
    public partial class frmMain : Form
    {
        private int childFormNumber1 = 0;

        public frmMain()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {

        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        /// <summary>
        /// 领卡验证
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 发卡补卡ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmGetCard childForm = new frmGetCard();
            childForm.MdiParent = this;
            //childForm.Text = "发卡补卡窗口";
            childForm.Show();
        }

        /// <summary>
        /// 卡挂失
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 卡挂失ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showForm(this, "KGS_fk", new KGS_fk("挂失"));
        }

        /// <summary>
        /// 解挂
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 解挂ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showForm(this, "KJG_fk", new KJG_fk("解挂"));
        }

        /// <summary>
        /// 退卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 退卡ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            showForm(this, "KTK_fk", new KTK_fk("退卡"));
        }

        /// <summary>
        /// 东屋授权
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 东屋授权ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showForm(this, "DW_fk", new DW_fk("授权"));
        }

        /// <summary>
        /// 待办任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 待办任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showForm(this, "dbrw", new dbrw());
        }

        private int childFormNumber = 0;
        logo FrmLogin;
        int groupid = 0;
        public DataTable user;
        private void MDIParent1_Load(object sender, EventArgs e)
        {
            FrmLogin = new logo();   //声时登录窗体，进行调用
            FrmLogin.Tag = 1;   //将登录窗体的Tag属性设为1，表示调用的是登录窗体
            FrmLogin.ShowDialog();
            FrmLogin.Dispose();
            if (FrmLogin.statr)
            {
                return;
            }
            FormStartScreen(this);
            user = FrmLogin.user;
            groupid = int.Parse(user.Rows[0]["GRPUP_ID"].ToString());
            int screen = Screen.AllScreens.Length;
        }

        public void FormStartScreen(Form form)
        {
            int i = 0;
            try
            {
                i = int.Parse(Properties.Settings.Default.dp.ToString());
            }
            catch (Exception)
            {
            }

            FormStartScreen(i, form);
        }

        public void FormStartScreen(int screen, Form form)
        {
            if (Screen.AllScreens.Length <= 1)
                return;
            if (Screen.AllScreens.Length < screen)
                return;
            form.StartPosition = FormStartPosition.Manual;
            form.Location = new System.Drawing.Point(Screen.AllScreens[screen].Bounds.X, Screen.AllScreens[screen].Bounds.Y);
            form.WindowState = FormWindowState.Maximized;
        }

        private bool showForm(Form MainForm, string Childname, Form ChildForm)
        {
            bool bReturn = true;
            for (int i = 0; i < MainForm.MdiChildren.Length; i++)
            {
                if (MainForm.MdiChildren[i].Name == Childname)
                {
                    MainForm.MdiChildren[i].BringToFront();
                    bReturn = false;
                    break;
                }
            }
            if (bReturn)
            {
                ChildForm.MdiParent = this;
                ChildForm.Show();
            }
            return bReturn;
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            ///

            //111	发卡/补卡
            //112	卡片挂失
            //113	卡片解挂
            //114	退卡

            //126	消费数据同步
            //127	办公楼授权
            //128	数据导入
            //129	考勤数据同步
            ///

            FrmLogin = new logo();   //声时登录窗体，进行调用
            FrmLogin.Tag = 1;   //将登录窗体的Tag属性设为1，表示调用的是登录窗体
            FrmLogin.ShowDialog();
            FrmLogin.Dispose();
            if (FrmLogin.statr)
            {
                return;
            }
            FormStartScreen(this);
            user = FrmLogin.user;
            groupid = int.Parse(user.Rows[0]["GRPUP_ID"].ToString());
            int Userid = int.Parse(user.Rows[0]["user_id"].ToString());
            int screen = Screen.AllScreens.Length;


            DataSet1TableAdapters.USER_FUNCTIONADPTableAdapter ustb = new DataSet1TableAdapters.USER_FUNCTIONADPTableAdapter();
            DataTable usertb = ustb.GetDatabyUserId(Userid);

            if (usertb.Select("function_ID=129 and czlx like '%操作%'").Count() > 0)
            {
                //129	考勤数据同步
                toolStripMenuItem6.Visible = true;
            }
            else
            {
                toolStripMenuItem6.Visible = false;
            }
            if (usertb.Select("function_ID=128 and czlx like '%操作%'").Count() > 0)
            {
                //128	数据导入
                toolStripMenuItem5.Visible = true;
            }
            else
            {
                toolStripMenuItem5.Visible = false;
            }

            if (usertb.Select("function_ID=127 and czlx like '%操作%'").Count() > 0)
            {
                //127	办公楼授权
                东屋授权ToolStripMenuItem.Visible = true;
            }
            else
            {
                东屋授权ToolStripMenuItem.Visible = false;
            }



            if (usertb.Select("function_ID=126 and czlx like '%操作%'").Count() > 0)
            {
                //126	消费数据同步
                toolStripMenuItem4.Visible = true;
            }
            else
            {
                toolStripMenuItem4.Visible = false;
            }



            if (usertb.Select("function_ID=114 and czlx like '%操作%'").Count() > 0)
            {
                //114	退卡
                退卡ToolStripMenuItem1.Visible = true;
            }
            else
            {
                退卡ToolStripMenuItem1.Visible = false;
            }



            if (usertb.Select("function_ID=113 and czlx like '%操作%'").Count() > 0)
            {
                //113	卡片解挂
                解挂ToolStripMenuItem.Visible = true;
            }
            else
            {
                解挂ToolStripMenuItem.Visible = false;
            }
            if (usertb.Select("function_ID=111 and czlx like '%操作%'").Count() > 0)
            {
                //111	发卡/补卡
                发卡补卡ToolStripMenuItem1.Visible = true;
            }
            else
            {
                发卡补卡ToolStripMenuItem1.Visible = false;
            }
            if (usertb.Select("function_ID=112 and czlx like '%操作%'").Count() > 0)
            {
                //112	卡片挂失
                卡挂失ToolStripMenuItem.Visible = true;
            }
            else
            {
                卡挂失ToolStripMenuItem.Visible = false;
            }

            //this.卡片维护ToolStripMenuItem.Visible = false;
            //this.扩展功能ToolStripMenuItem.Visible = false;
            //this.发卡统计表ToolStripMenuItem.Visible = false;
            //this.待办任务ToolStripMenuItem.Visible = false;
        }

        /// <summary>
        /// 采集数据验证
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            showForm(this, "frm", new CheckGather1());
        }

        /// <summary>
        /// 发卡/补卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 发卡补卡ToolStripMenuItem1_Click_1(object sender, EventArgs e)
        {
            showForm(this, "fk", new fk("发卡"));
        }

        /// <summary>
        /// 发卡统计表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 发卡统计表ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 关于
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            kwzxAbout ka = new kwzxAbout();
            ka.ShowDialog();
        }

        /// <summary>
        /// 非正式员导入功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 非正式员导入功能IToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 非正式员工Excel文件验证及入库操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 非正式员工Excel文件验证及入库操作FToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 施普玛照片对比
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 照片对比ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showForm(this, "SPM_fk", new SPM_fk("照片对比"));
        }

        /// <summary>
        /// 更换皮肤
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 皮肤ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.InitialDirectory = @"..\skins";
            dialog.Filter = "skin files (*.skn)|*.skn";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                skinUI1.LoadSkinFile(dialog.FileName);
                //  this.Text = Path.GetFileName(dialog.FileName);
            }
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            showForm(this, "frmScmCard", new frmScmCard());
        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            //showForm(this,"frmScmDataSyn",new frmScmDataSyn());
            showForm(this, "frmScmSyn", new frmScmSyn());
        }

        private void 批量授权ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showForm(this, "DDS_user", new DDS_user());
        }

        private void 批量发卡ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            showForm(this, "lyb", new lyb());
        }

        private void 非正式员工Excel验证后直接入库ZToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {

            DialogResult dr = MessageBox.Show("是否退出卡务中心系统？", "取消提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.Yes)
            {
                e.Cancel = false;
            }
            else
            {
                e.Cancel = true;
            }
        }

        private void dDS接口测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Spread sp = new Spread();
                sp.StartConnect();
                string message = "<perform><cmd>DisplayMessage</cmd><param><query><Param1>测试成功  " + DateTime.Now.ToString() + " </Param1></query></param></perform>";
                string pcname = Properties.Settings.Default.pcname_dds;
                sp.SpreadSend(pcname, message);
                sp.DesInit();
                MessageBox.Show("已发送");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void toolStripMenuItem7_Click(object sender, EventArgs e)
        {
            showForm(this, "user2impExcel", new ImpExcel.user2impExcel("导入"));
        }

        private void 非正式员工Excel验证后直接入库FToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showForm(this, "ExcelOper", new ImpExcel.ExcelOper("入库"));
        }

        private void 正式员工Excel验证后直接入库ZToolStripMenuItem_Click(object sender, EventArgs e)
        {
            showForm(this, "zsImpExcel", new ImpExcel.zsImpExcel("导入"));
        }

        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {


            // showForm(this, "kqtb", new kqtb(""));
            showForm(this, "frmAttendance", new frmAttendance());
        }





    }
}
